import spock.lang.Specification

import java.util.concurrent.Callable
import java.util.concurrent.Executors
import java.util.concurrent.Future

/**
 * Created at 2017/11/17 12:22
 * @author gongweixin
 */
class ThreadExample extends Specification {

    def "test callable"() {
        def executor = Executors.newFixedThreadPool(10)
        Future<Integer> future = executor.submit({
            1
        } as Callable)

        expect:
        1 == future.get()
    }

    def "test thread expception"() {
        def executor = Executors.newFixedThreadPool(10)
        Future<Integer> future = executor.submit({
            throw new RuntimeException("123")
        } as Callable)

        expect:
        1 == future.get()
    }
}
